//
// Created by Sugars Mac on 2021/9/1.
//

#include "common.h"
#include <stdio.h>

void printTable(struct distance_table *dtptr, int me) {
    printf("   D%d | 0  1  2  3 \n", me);
    printf("   ---+------------\n");
    for (int i = 0; i < 4; ++i) {
        printf("   %d  | ", i);
        for (int j = 0; j < 4; ++j) {
            printf("%d  ", dtptr->costs[i][j]);
        }
        printf("\n");
    }
    printf("\n");
}

int min(int a, int b) {
    return a > b ? b : a;
}

void send2Neighbors(struct distance_table *dtptr, int me) {
    for (int i = 0; i < 4; ++i) {
        if (i == me || dtptr->costs[me][i] == 999) {
            continue;
        }
        struct rtpkt packet;
        creatertpkt(&packet, me, i, dtptr->costs[me]);
        tolayer2(packet);
    }
}